package com.java.cloud.storage.dao;

import com.java.cloud.storage.entity.Storage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * 库存
 *
 * @author jl
 * @since 2020-03-13 11:44:37
 */
@Mapper
public interface StorageDao extends BaseMapper<Storage> {

	@Update("UPDATE `t_storage` SET `used` = `used` + #{count} , `residue` = `residue` - #{count} WHERE `product_id` = #{productId} AND (`residue` - #{count}) > 0 ")
	int decrease(@Param("productId") Long productId, @Param("count") Integer count);

}
